package model

import (
	"gorm.io/gorm"
	"types"
)

// 用户表
type User struct {
	gorm.Model
	ClassId  int    `gorm:"type:int(11);not null;comment:课程id"`
	Username string `gorm:"type:varchar(30);index;not null;comment:用户名称"`
	Password string `gorm:"type:char(32);not null;comment:用户密码"`
	Phone    string `gorm:"type:char(11);not null;comment:用户手机号"`
	Age      int    `gorm:"type:int(11);not null;comment:用户年龄"`
	Sex      int    `gorm:"type:int(11);not null;comment:用户性别 1.男 0.女"`
	Slat     string `gorm:"type:varchar(30);not null;comment:盐"`
}

// 用户注册
func (u *User) UserAdd() error {
	return types.Db.Create(&u).Error
}

// 用户登录
func (u *User) UserLogin() (user *User, err error) {
	err = types.Db.Where("username = ?", u.Username).Find(&user).Error
	return
}
